package com.gs.cd.service.resource.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gs.cd.model.resource.SysResourceGroupOwnResource;
import com.gs.cd.service.resource.mapper.SysResourceGroupOwnResourceMapper;
import com.gs.cd.service.resource.service.SysResourceGroupOwnResourceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.NonNull;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author seven
 * @since 2020-12-22
 */
@Service
public class SysResourceGroupOwnResourceServiceImpl extends ServiceImpl<SysResourceGroupOwnResourceMapper, SysResourceGroupOwnResource> implements SysResourceGroupOwnResourceService {

    @Override
    public List<SysResourceGroupOwnResource> listByResourceGroupCode(String saleCode, String resourceGroupCode) {
        return list(new QueryWrapper<SysResourceGroupOwnResource>().lambda()
                .eq(SysResourceGroupOwnResource::getSysResourceGroupCode, resourceGroupCode)
                .eq(SysResourceGroupOwnResource::getSysSaleCode, saleCode));
    }

    @Override
    public List<SysResourceGroupOwnResource> listByResourceGroupCodes(String saleCode, Collection<String> resourceGroupCodes) {
        if (resourceGroupCodes.isEmpty()) return new ArrayList<>();
        return list(new QueryWrapper<SysResourceGroupOwnResource>().lambda().eq(SysResourceGroupOwnResource::getSysSaleCode, saleCode)
                .in(SysResourceGroupOwnResource::getSysResourceGroupCode, resourceGroupCodes));
    }

    @Override
    public boolean removeByResourceGroupCodes(String saleCode, @NonNull Set<String> resourceGroupCodes) {
        if (resourceGroupCodes.isEmpty()) return true;
        return remove(new QueryWrapper<SysResourceGroupOwnResource>().lambda().eq(SysResourceGroupOwnResource::getSysSaleCode, saleCode)
                .in(SysResourceGroupOwnResource::getSysResourceGroupCode, resourceGroupCodes));
    }
}
